home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0069_Is Previous Instance running?.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-24  |  895 b   |  38 lines

  1. {usual stuff at the top of the project source file
  2. var hwnd: Word;
  3.  
  4. begin
  5.   if hPrevInst = 0 then
  6.   begin
  7.     Application.CreateForm(TForm1, Form1);
  8.     Application.Run;
  9.   end
  10.   else
  11.   begin
  12.     hwnd := FindWindow('TForm1', nil);
  13.     if (not IsWindowVisible(hwnd)) then
  14.     begin
  15.       ShowWindow(hwnd, sw_ShowNormal);
  16.       PostMessage(hwnd, wm_User, 0, 0);
  17.     end;
  18.     else
  19.       SetWindowPos(hwnd, HWND_TOP, 0,0,0,0,
  20.         SWP_NOSIZE or SWP_NOMOVE);
  21.   end;
  22. end.
  23. ====================================================
  24.  
  25. In the form's PAS file add a message response function for the wm_User
  26. message.
  27.  
  28. ====================================================
  29. {in the form declaration}
  30. public
  31.   procedure WMUser(var msg: TMessage); message wm_User;
  32.  
  33. {in the implementation section}
  34. procedure TForm1.WMUser(var msg: TMessage);
  35. begin
  36.   Application.Restore;
  37. end;
  38.